package com.allenyuan.render;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.geom.CubicCurve2D;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;

public class ScreenRenderer extends AbstractRenderer {
	
	private Graphics2D g;
	
	public ScreenRenderer() {
	}
	
	public ScreenRenderer(Graphics2D g) {
		this.g = g;
	}
	
	public void setGraphics(Graphics2D g) {
		this.g = g;
		setStroke(new RenderStroke(false, 1));
	}

	@Override
	public void drawCircle(int x, int y, int r) {
		// TODO Auto-generated method stub
		g.drawOval(x - r, y - r, r + r, r + r);
	}

	@Override
	public void drawLine(int x1, int y1, int x2, int y2) {
		// TODO Auto-generated method stub
		g.drawLine(x1, y1, x2, y2);
	}

	@Override
	public void drawText(int x, int y, String text, String font, int size) {
		// TODO Auto-generated method stub
		Font f = Font.getFont(font);
		g.setFont(f);
		g.drawString(text, x, y);
	}

	@Override
	public void drawRectangle(int x, int y, int width, int height) {
		// TODO Auto-generated method stub
		g.drawRect(x, y, width, height);
	}

	@Override
	public void setTransform(double[] transform) {
		// TODO Auto-generated method stub
		g.setTransform(new AffineTransform(transform));
	}

	@Override
	public void setPenColor(int color) {
		// TODO Auto-generated method stub
		g.setColor(new Color(color));
	}

	@Override
	public void fill(int color) {
		// TODO Auto-generated method stub
		
	}

	public Graphics2D getG() {
		return g;
	}

	@Override
	public void setStroke(RenderStroke stroke) {
		// TODO Auto-generated method stub
		super.setStroke(stroke);
		Stroke s = null;
		if (stroke.isDash()) {
			s = new BasicStroke(stroke.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{16, 4}, 0); 
		}
		else {
			s = new BasicStroke(stroke.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
		}
		g.setStroke(s);
	}

	@Override
	public void drawBezier3(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3) {
		// TODO Auto-generated method stub
		CubicCurve2D.Double cc = new CubicCurve2D.Double();
		cc.setCurve(x0, y0, x1, y1, x2, y2, x3, y3);
		g.draw(cc);
	}

	@Override
	public void drawImage(int x, int y, int width, int height, int[] img) {
		// TODO Auto-generated method stub
		
	}
;}
